package dimensional.traveler.server.services;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import dimensional.traveler.client.services.UserService;
import dimensional.traveler.shared.SaveGameInfo;

public class UserServiceImpl implements UserService {

	@Override
	public SaveGameInfo getSaveGameInfoForUser(String userName) {
		File saveGameDirectory = new File("saves/" + userName);
		if (saveGameDirectory.list().length == 0) {
			return new SaveGameInfo();
		} else {
			return new SaveGameInfo(true, true);
		}
	}

	@Override
	public List<String> getSavedGamesForUser(String userName) {
		File saveGameDirectory = new File("saves/" + userName);
		String[] fileNames = saveGameDirectory.list();
		List<String> filesNameList = new ArrayList<>(fileNames.length);
		Collections.addAll(filesNameList, fileNames);
		return filesNameList;
	}

}
